package com.topisv.tms.utils;

import java.util.ArrayList;
import java.util.List;

public class SplitUtil {
	/**
	 * 按指定长度分割list
	 * @param orig
	 * @param batchSize
	 * @return List<List<T>>
	 */
	public static <T> List<List<T>> split(List<T> orig, int batchSize) {
		int totalSize = orig.size();
		int page = (int) Math.ceil(totalSize * 1.0 / batchSize);
		List<List<T>> rs = new ArrayList<List<T>>(page);
		for (int i = 0; i < page; i++) {
			rs.add(orig.subList(i * batchSize, Math.min(totalSize, (i + 1) * batchSize)));
		}
		return rs;
	}

}
